package original;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TestParameterSQLConcat {
    public static void main(String[] args) throws Exception {
        Connection con = null;
        PreparedStatement statement = null;
        ResultSet query = null;
        try {
            String sql = "select * from STUDENT where sname like '%' ? '%'";
            DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
            con = DriverManager.getConnection("jdbc:mysql://188.131.246.195:3306/mybatis_learn", "root", "601220zjh...");
            statement = con.prepareStatement(sql);
            statement.setString(1, "王");
            query = statement.executeQuery();
            while (query.next()) {
                System.out.println(query.getObject("SNO"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (query != null) {
                query.close();
            }
            if (statement != null) {
                statement.close();
            }
            if (con != null) {
                con.close();
            }
        }
    }
}